package com.xpf.service.process;

import com.xpf.service.process.entity.BpmStartDTO;
import com.xpf.service.process.entity.ProcessCommonDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Slf4j
@Service
public abstract class LanDrayCommonProcessStrategy<T extends ProcessCommonDTO> {

    /** 审批事件编码 **/
    protected String eventCode;

    /** 审批标题 **/
    protected String processSubject;

    /** 审批processKey **/
    protected String processKey;

    @Autowired
    private LanDrayProcessServiceImpl lanDrayProcessService;

    /**
     * 提交审批前的处理
     * @param object
     * @return
     */
    public abstract void submitApprovalBefore(T object);

    /**
     * 组装表单信息，子类实现
     *
     * @Param dataId 业务id
     * @Param object 业务对象
     **/
    protected abstract void getFormList(BpmStartDTO bpmStartDTO, T object);


    public final String createProcessBPM(String dataId, T object) {
        //提交审批前处理
        submitApprovalBefore(object);
        //拼装审批信息
        BpmStartDTO bpmStartDTO = new BpmStartDTO();
        getFormList(bpmStartDTO, object);
        //调用审批接口执行审批
        String result = lanDrayProcessService.startProcess(bpmStartDTO);
        if ("200".equals(result)){
            System.out.println("审批发起调用成功");
        }

        return "审批发起调用成功！";
    }

    /**
     * 获取processKey
     */
    public String getProcessKey() {
        return processKey;
    }
}
